﻿using System;
using System.Threading.Tasks;
using HelloWorld.ActionFilters;
using HelloWorld.ViewModels.Home;
using Phoenix;
using Phoenix.ActionResults;

namespace HelloWorld.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return Page(new IndexViewModel());
        }

        public ActionResult ThrowError()
        {
            throw new InvalidOperationException("Some exception during controller action");
        }

        [NetworkRequiredFilter]
        public ActionResult NetworkRequired()
        {
            return Nothing();
        }

        public PageActionResult ViewDoesntExist()
        {
            return Page();
        }

        public ActionResult FatalError()
        {
            Context.Host.ErrorReporter.ReportException(new InvalidOperationException(), "Example extra info", true);
            return MessageBox("Exit application and re-launch to trigger error report");
        }

        public ActionResult NavigationExamples()
        {
            return Page(new NavigationExamplesViewModel());
        }

        public ActionResult Tombstoning()
        {
            return Page(new TombstoningViewModel());
        }

        public Task<ActionResult> AsyncWithResultException()
        {
            return Task.Factory.StartNew<ActionResult>(() => { throw new InvalidOperationException(); });
        }

        public ActionResult ViewWithExceptions()
        {
            return Page(new PageWithExceptionsViewModel());
        }

        public Task<ActionResult> GetMessage()
        {
            return TaskEx.FromResult<ActionResult>(Result("Hi!"));
        }
    }
}